<p class="Paragraph"><help:paragraphinfo state="U" number="10" xmlns:help="http://openoffice.org/2000/help"/><span class="T1">Counter:</span> Loop counter initially assigned the value to the right of the equal sign (start). Only numeric variables are valid. The loop counter increases or decreases according to the variable Step until End is passed.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="11" xmlns:help="http://openoffice.org/2000/help"/><span class="T1">Start:</span> Numeric variable that defines the initial value at the beginning of the loop.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="12" xmlns:help="http://openoffice.org/2000/help"/><span class="T1">End:</span> Numeric variable that defines the final value at the end of the loop.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="13" xmlns:help="http://openoffice.org/2000/help"/><span class="T1">Step:</span> Sets the value by which to increase or decrease the loop counter. If Step is not specified, the loop counter is incremented by 1. In this case, End must be greater than Start. If you want to decrease Counter, End must be less than Start, and Step must be assigned a negative value.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="14" xmlns:help="http://openoffice.org/2000/help"/>The <span class="T1">For...Next</span> loop repeats all of the statements in the loop for the number of times that is specified by the parameters.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="15" xmlns:help="http://openoffice.org/2000/help"/>As the counter variable is decreased, <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> Basic checks if the end value has been reached. As soon as the counter passes the end value, the loop automatically ends.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="16" xmlns:help="http://openoffice.org/2000/help"/>It is possible to nest <span class="T1">For...Next</span> statements. If you do not specify a variable following the <span class="T1">Next</span> statement, <span class="T1">Next</span> automatically refers to the most recent <span class="T1">For</span> statement.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="17" xmlns:help="http://openoffice.org/2000/help"/>If you specify an increment of 0, the statements between <span class="T1">For</span> and <span class="T1">Next</span> are repeated continuously.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="18" xmlns:help="http://openoffice.org/2000/help"/>When counting down the counter variable, <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> Basic checks for overflow or underflow. <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>The loop ends when Counter exceeds End (positive Step value) or is less than End (negative Step value).</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="19" xmlns:help="http://openoffice.org/2000/help"/>Use the <span class="T1">Exit For</span> statement to exit the loop unconditionally. This statement must be within a <span class="T1">For...Next</span> loop. Use the <span class="T1">If...Then</span> statement to test the exit condition as follows:</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="25" xmlns:help="http://openoffice.org/2000/help"/>Note: In nested <span class="T1">For...Next</span> loops, if you exit a loop unconditionally with <span class="T1">Exit For</span>, only one loop is exited.</p>
<p class="Paragraph"><help:paragraphinfo state="U" number="27" xmlns:help="http://openoffice.org/2000/help"/>The following example uses two nested loops to sort a string array with 10 elements ( sEntry() ), that are first filled with various contents:</p>